/********************************************************
 *
 * FILE NAME:   butterfilter.h
 *
 * DESCRIPTION:
 *  Module with Butterworth filter
 *
 ********************************************************/

#ifndef BUTTERFILTER_H
#define BUTTERFILTER_H

/********************************************************/
/*              Includes                                */
/********************************************************/
#include "filter.h"

#include <QApplication>

/********************************************************/
/*              Defines                                 */
/********************************************************/

/********************************************************/
/*              Macros                                  */
/********************************************************/

/********************************************************/
/*              Typedefs                                */
/********************************************************/
class ButterFilter;

class ButterFilter: public Filter
{
    Q_OBJECT

    public:
        enum type_e {LOWPASS, HIGHPASS};
        Q_ENUMS(type_e)

        /********************************************************
         * Function Name    :   ButterFilter
         *
         * Description      :   Constructor, calculates coefficients of Butterworth filter
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :   size_t N = fiter order
         *                      sample_t Wn = cutoff frequency (normalized, in range [0, 0.5])
         *                      type_e filterType = type of the filter (LOWPASS / HIGHPASS)
         *                      size_t burstLength = number of samples that can be processed in burst
         *
         * Returns          :
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com
         *
         ********************************************************/
        ButterFilter(Filter *parent = 0);

        Q_INVOKABLE void init(int N, int burstLength);

        Q_INVOKABLE void setCoefficients(double Wn,int filterType);


        /********************************************************
         * Function Name    :   ~ButterFilter
         *
         * Description      :   Destructor
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         * Returns          :
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com
         *
         ********************************************************/
        ~ButterFilter();

    private:
        /********************************************************
         * Function Name    :   factorial
         *
         * Description      :   Computes the factorial of num
         *
         * Side effects     :
         *
         * Comment          :   Recursive function
         *
         * Parameters       :   unsigned int num = number value
         *
         * Returns          :   factorial of num
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com
         *
         ********************************************************/
        unsigned int factorial(unsigned int num);

        /********************************************************
         * Function Name    :   bilinearTransform
         *
         * Description      :   Transformation from S to Z domain (analog to digital coeffients transformation)
         *
         * Side effects     :
         *
         * Comment          :   S = 2 * (z - 1) / (z + 1)
         *
         * Parameters       :   sample_t *sCoeff = coeffients in S domain
         *                      int N = order of filter
         *                      int n = desired Z domain coeffient
         *
         * Returns          :   coeffient in Z domain
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com
         *
         ********************************************************/
        sample_t bilinearTransform(sample_t *sCoeff, int N, int n);
};

/********************************************************/
/*              Functions Declarations                  */
/********************************************************/

/********************************************************/
/*              Variables Declarations (IMPORT)         */
/********************************************************/

#endif /* BUTTERFILTER_H */
